From 5604d8e8dcdd1f6ca6cc8e4000c17344f19f02be Mon Sep 17 00:00:00 2001 From: robertlipe Date: Wed, 23 Oct 2013 03:02:13 +0000 Subject: [PATCH] Begin landing NEW_STRINGS work: common utilities. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4637 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/defs.h | 8 ++++---- gpsbabel/route.cc | 31 +++++++++++++++++++++++++------ gpsbabel/util.cc | 11 +++++++++-- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 5694da8b0..444dacb97 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -712,10 +712,10 @@ geocache_container gs_mkcont(const QString& t); route_head* route_head_alloc(void); void route_add(waypoint*); void route_add_wpt(route_head* rte, waypoint* wpt); -void route_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits); +void route_add_wpt_named(route_head* rte, waypoint* wpt, const QString& namepart, int number_digits); void route_del_wpt(route_head* rte, waypoint* wpt); void track_add_wpt(route_head* rte, waypoint* wpt); -void track_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits); +void track_add_wpt_named(route_head* rte, waypoint* wpt, const QString& namepart, int number_digits); void track_del_wpt(route_head* rte, waypoint* wpt); void route_add_head(route_head* rte); void route_del_head(route_head* rte); @@ -781,7 +781,7 @@ short_handle MKSHORT_NEW_HANDLE(DEBUG_PARAMS); #define mkshort( a, b) MKSHORT(a,b,__FILE__, __LINE__) #define mkshort_new_handle() MKSHORT_NEW_HANDLE(__FILE__,__LINE__) #endif -char* mkshort_from_wpt(short_handle h, const waypoint* wpt); +String mkshort_from_wpt(short_handle h, const waypoint* wpt); void mkshort_del_handle(short_handle* h); void setshort_length(short_handle, int n); void setshort_badchars(short_handle, const char*); @@ -1018,7 +1018,7 @@ const char* get_cache_icon(const waypoint* waypointp); const char* gs_get_cachetype(geocache_type t); const char* gs_get_container(geocache_container t); char* xml_entitize(const char* str); -char* html_entitize(const char* str); +char* html_entitize(const QString& str); char* strip_html(const utf_string*); char* strip_nastyhtml(const QString& in); char* convert_human_date_format(const char* human_datef); /* "MM,YYYY,DD" -> "%m,%Y,%d" */ diff --git a/gpsbabel/route.cc b/gpsbabel/route.cc index 5b469575c..1788d8fc6 100644 --- a/gpsbabel/route.cc +++ b/gpsbabel/route.cc @@ -77,12 +77,14 @@ route_head_alloc(void) static void any_route_free(route_head* rte) { +#if !NEW_STRINGS if (rte->rte_name) { xfree(rte->rte_name); } if (rte->rte_desc) { xfree(rte->rte_desc); } +#endif waypt_flush(&rte->waypoint_list); if (rte->fs) { fs_chain_destroy(rte->fs); @@ -151,7 +153,11 @@ common_route_by_name(queue* routes, const char* name) QUEUE_FOR_EACH(routes, elem, tmp) { rte = (route_head*) elem; +#if NEW_STRINGS + if (rte->rte_name == name) { +#else if (0 == strcmp(rte->rte_name, name)) { +#endif return rte; } } @@ -172,20 +178,21 @@ route_find_track_by_name(const char* name) } static void -any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth, const char* namepart, int number_digits) +any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth, const QString& namepart, int number_digits) { ENQUEUE_TAIL(&rte->waypoint_list, &wpt->Q); rte->rte_waypt_ct++; /* waypoints in this route */ if (ct) { (*ct)++; } - if (synth && !wpt->shortname) { #if NEW_STRINGS + if (synth && wpt->shortname.isEmpty()) { char *t; - xasprintf(&t, "%s%0*d", namepart, number_digits, *ct); + xasprintf(&t, "%s%0*d", CSTRc(namepart), number_digits, *ct); wpt->shortname = t; #else - xasprintf(&wpt->shortname,"%s%0*d", namepart, number_digits, *ct); + if (synth && !wpt->shortname) { + xasprintf(&wpt->shortname,"%s%0*d", CSTR(namepart), number_digits, *ct); #endif wpt->wpt_flags.shortname_is_synthetic = 1; } @@ -193,7 +200,7 @@ any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth, const char } void -route_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits) +route_add_wpt_named(route_head* rte, waypoint* wpt, const QString& namepart, int number_digits) { // First point in a route is always a new segment. // This improves compatibility when reading from @@ -213,7 +220,7 @@ route_add_wpt(route_head* rte, waypoint* wpt) } void -track_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits) +track_add_wpt_named(route_head* rte, waypoint* wpt, const QString& namepart, int number_digits) { // First point in a track is always a new segment. // This improves compatibility when reading from @@ -239,7 +246,11 @@ route_find_waypt_by_name(route_head* rh, const char* name) QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) { waypoint* waypointp = (waypoint*) elem; +#if NEW_STRINGS + if (waypointp->shortname == name) { +#else if (0 == strcmp(waypointp->shortname, name)) { +#endif return waypointp; } } @@ -590,7 +601,10 @@ void track_recompute(const route_head* trk, computed_trkdata** trkdatap) double tot_hrt = 0.0; int pts_cad = 0; double tot_cad = 0.0; +#if NEW_STRINGS +#else char tkptname[100]; +#endif computed_trkdata* tdata = (computed_trkdata*)xcalloc(1, sizeof(computed_trkdata)); if (trkdatap) { @@ -693,10 +707,15 @@ void track_recompute(const route_head* trk, computed_trkdata** trkdatap) } } prev = thisw; +#if NEW_STRINGS + if (thisw->shortname.isEmpty()) { + thisw->shortname = QString("%1-%2").arg(trk->rte_name).arg(tkpt); +#else if (!thisw->shortname || !thisw->shortname[0]) { snprintf(tkptname, sizeof(tkptname), "%s-%d", trk->rte_name ? CSTRc(trk->rte_name) : "" , tkpt); thisw->shortname = xstrdup(tkptname); +#endif } tkpt++; } diff --git a/gpsbabel/util.cc b/gpsbabel/util.cc index 20e82afca..891cf3381 100644 --- a/gpsbabel/util.cc +++ b/gpsbabel/util.cc @@ -279,12 +279,15 @@ xasprintf(char** strp, const char* fmt, ...) } #if NEW_STRINGS int -xasprintf(String* strp, const char* fmt, ...) +xasprintf(QString* strp, const char* fmt, ...) { va_list args; int res; va_start(args, fmt); - res = xvasprintf(&strp->s_, fmt, args); + char *cstrp; + res = xvasprintf(&cstrp, fmt, args); + *strp = cstrp; + xfree(cstrp); va_end(args); return res; @@ -1735,6 +1738,10 @@ char* html_entitize(const char* str) { return entitize(str, 1); } +char* html_entitize(const QString& str) +{ + return entitize(CSTR(str), 1); +} /* * xml_tag utilities -- 2.30.2